<!--  -->
<template>
  <div class="school_menu_list" v-loading="loading">
    <div class="list_left_menu">
      <div class="menu_items">
        <div
          class="item"
          v-for="(item, index) in fatherMenu"
          :key="item.moduleid"
          :class="index == status ? 'active' : ''"
          @click="getChildMenu(index)"
        >
          <img :src="item.icon" alt="" class="i_icon" />
          <div class="name">{{ item.name }}</div>
        </div>
      </div>
    </div>
    <div class="list_right_menu">
      <div class="menu_items">
        <div class="item" v-for="item in childMenu" :key="item.moduleid">
          <div @click="viewInfo(item)" class="content">
            <img :src="item.icon" alt="" class="i_icon" />
            <div class="name">{{ item.name }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';

export default {
  name: "stuNormalApply",
  //import引入的组件需要注入到对象中才能使用
  props: {
    menu: {
      type: [Array, Object],
    },
  },
  components: {},
  data() {
    //这里存放数据
    return {
      loading: false,
      status: 0,
      fatherMenu: [],
      childMenu: [],
    };
  },
  //监听属性 类似于data概念
  computed: {
    // childMenu(){
    //   return this.menu.childrens[this.status].childrens
    // },
    userInfo() {
      return this.$store.state.userInfo;
    },
    lang() {
      return this.$i18n.locale;
    },
  },
  //监控data中的数据变化
  watch: {
    menu: {
      handler: function (newVal, oldVal) {
        this.MenuFormat(newVal);
      },
      deep: true,
    },
  },
  //方法集合
  methods: {
    MenuFormat(data) {
      this.loading = false;
      this.fatherMenu = data;
      this.childMenu = data[this.status].childrens;
    },
    getChildMenu(status) {
      this.status = status;
      this.childMenu = this.menu[status].childrens;
    },
    viewInfo(data) {
      // :to="{name:item.url,query:{apply:item.moduleid}}"
      this.$api
        .post("/reckon/verifyMenu", {
          moduleid: data.moduleid,
        })
        .then((res) => {
          this.$router.push({
            name: data.url,
            query: {
              user: this.$store.state.userInfo.correlationid,
              apply: data.moduleid,
            },
          });
        })
        .catch((e) => {});
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    // if(this.menu.length && this.menu.length==0){
    //   this.loading = true
    // }
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang='stylus' scoped>
.school_menu_list {
  position: relative;
  padding: 0 20px 20px;
  display: flex;

  .list_left_menu {
    width: 130px;
    position: relative;
    margin-right: 20px;

    .menu_items {
      .item {
        cursor: pointer;
        width: 130px;
        height: 120px;
        background: $aqua;
        display: flex;
        justify-content: center;
        align-items: center;
        flex-direction: column;
        margin-top: 10px;
        position: relative;

        &:first-child {
          margin: 0;
        }

        &.active {
          border-right: 2px solid #FA6400;

          &::after {
            position: absolute;
            right: -8px;
            content: '';
            display: block;
            width: 0;
            height: 0;
            border-left: 8px solid #FA6400;
            border-top: 10px solid transparent;
            border-bottom: 10px solid transparent;
          }
        }

        .i_icon {
          width: 40px;
          height: 40px;
        }

        .name {
          line-height: 1.6;
        }
      }
    }
  }

  .list_right_menu {
    flex-grow: 1;
    background: $aqua;

    .menu_items {
      position: relative;
      padding: 10px;
      display: flex;
      flex-wrap: wrap;

      .item {
        position: relative;
        flex: 0 1 140px;
        text-align: center;
        cursor: pointer;

        .content {
          margin: 10px;
          min-width: 100px;
          box-sizing: border-box;
          display: flex;
          justify-content: center;
          align-items: center;
          flex-direction: column;

          .i_icon {
            width: 60px;
            height: 60px;
          }

          .name {
            white-space: pre-wrap;
            word-break: break-word;
            text-align: center;
            overflow: hidden;
            margin-top: 10px;
            color: $darkblack;
          }
        }
      }
    }
  }
}
</style>